package com.ruoyi.project.supplier.accounts.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.supplier.accounts.domain.SupAccounts;
import com.ruoyi.project.supplier.accounts.service.ISupAccountsService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 第三方系统对接Controller
 * 
 * @author lindor
 * @date 2020-04-07
 */
@Controller
@RequestMapping("/supplier/accounts")
public class SupAccountsController extends BaseController
{
    private String prefix = "supplier/accounts";

    @Autowired
    private ISupAccountsService supAccountsService;

    @RequiresPermissions("supplier:accounts:view")
    @GetMapping()
    public String accounts()
    {
        return prefix + "/accounts";
    }

    /**
     * 查询第三方系统对接列表
     */
    @RequiresPermissions("supplier:accounts:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(SupAccounts supAccounts)
    {
        startPage();
        List<SupAccounts> list = supAccountsService.selectSupAccountsList(supAccounts);
        return getDataTable(list);
    }

    /**
     * 导出第三方系统对接列表
     */
    @RequiresPermissions("supplier:accounts:export")
    @Log(title = "第三方系统对接", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(SupAccounts supAccounts)
    {
        List<SupAccounts> list = supAccountsService.selectSupAccountsList(supAccounts);
        ExcelUtil<SupAccounts> util = new ExcelUtil<SupAccounts>(SupAccounts.class);
        return util.exportExcel(list, "accounts");
    }

    /**
     * 新增第三方系统对接
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存第三方系统对接
     */
    @RequiresPermissions("supplier:accounts:add")
    @Log(title = "第三方系统对接", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(SupAccounts supAccounts)
    {
        return toAjax(supAccountsService.insertSupAccounts(supAccounts));
    }

    /**
     * 修改第三方系统对接
     */
    @GetMapping("/edit/{supId}")
    public String edit(@PathVariable("supId") Long supId, ModelMap mmap)
    {
        SupAccounts supAccounts = supAccountsService.selectSupAccountsById(supId);
        mmap.put("supAccounts", supAccounts);
        return prefix + "/edit";
    }

    /**
     * 修改保存第三方系统对接
     */
    @RequiresPermissions("supplier:accounts:edit")
    @Log(title = "第三方系统对接", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(SupAccounts supAccounts)
    {
        return toAjax(supAccountsService.updateSupAccounts(supAccounts));
    }

    /**
     * 删除第三方系统对接
     */
    @RequiresPermissions("supplier:accounts:remove")
    @Log(title = "第三方系统对接", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(supAccountsService.deleteSupAccountsByIds(ids));
    }
}
